package com.jiang.action;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jiang.vo.Emp;
import com.jiang.vo.ResultData;

@Controller
@RequestMapping("/emp/action/*")
public class EmpAction extends BaseAction{

	@RequestMapping("getEmp")
	public ModelAndView getEmp(int empno) {
		System.out.println("获取到了参数empno:" + empno);
		return null;
		
	}
	
	@RequestMapping("addEmp")
	public ModelAndView addEmp(Emp emp,HttpServletResponse response) {
		System.out.println("heelo");
		Emp emp2 = new Emp();
		emp2.setEmpNo("121");
		try {
			response.getWriter().print(emp2);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("getEmp2")
	@ResponseBody
	public Emp getEmp() throws Exception{
		
		Emp emp = new Emp();
		emp.setEmpNo("将好着呢购物");
		emp.setSalary(10002.0);
		String birthday = "1986-07-04";
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		Date _birthday = sf.parse(birthday);
		emp.setBirthday(_birthday);
		return emp;
	}
	
	@RequestMapping(value = "getEmp3",produces ="text/plain;charset=UTF-8" )
	@ResponseBody
	public String getEmp3() throws Exception{
		
		return "蒋正午";
	}

	@Override
	public String getUploadDir() {
		return "/upload/";
	}
	
	@RequestMapping("add")
	@ResponseBody
	public ResultData dopost(Emp emp) {
		
		System.out.println("增加员工成功!" + emp);
		ResultData rd = new ResultData(true, null);
		return rd;
	}
	@RequestMapping("delete")
	@ResponseBody
	public ResultData doDelete(int empNo) {
		System.out.println("删除员工成功!" + empNo);
		ResultData rd = new ResultData(true, null);
		return rd;
	}
	
	@RequestMapping("get")
	@ResponseBody
	public ResultData doGet() {
		System.out.println("查询员工成功!");
		Emp emp = new Emp();
		emp.setEmpNo("233");
		emp.setSalary(20.20);
		emp.setBirthday(new Date());
		ResultData rd = new ResultData(true, emp);
		return rd;
	}

	@RequestMapping("update")
	@ResponseBody
	public ResultData doupdate(Emp emp) {
		
		System.out.println("修改员工成功!" + emp);
		ResultData rd = new ResultData(true, null);
		return rd;
	}
	
	
}
